package creator.ui.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.URL;

public class WriteData {

  public static void WriteObjectInLocal(Object object, String path) {
    try {
      String uri = WriteData.class.getResource(path).getPath();

      File file = new File(
        uri
          .replace("file:/", "")
          .replace("FlappyBird.jar!/", "")
          .replace("file:\\", "")
          .replace("FlappyBird.jar!\\", "")
          .substring(1)
      );

      ObjectOutputStream out = new ObjectOutputStream(
        new FileOutputStream(file)
      );
      out.writeObject(object);
      out.flush();
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
